package com.briup.jd2511.jd2511bookstore.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;

/**
 * 切面类测试各种通知
 */
//@Aspect
//@Component
@Slf4j
@Order(3) // 优先级排序，数字小的优先级大
public class MyAspect1 {

    // 定义统一的切入点
    @Pointcut("execution(* com.briup.jd2511.jd2511bookstore.service.impl.*.*(..))")
    public void pc(){}

    // 前置通知
    @Before("pc()")
    public void before(JoinPoint joinPoint){
        log.error("前置通知");
    }
    // 后置通知
    @After("pc()")
    public void after(JoinPoint joinPoint){
        log.error("后置通知");
    }
    // 环绕通知
    @Around("execution(* com.briup.jd2511.jd2511bookstore.service.impl.*.*(..))")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        log.error("环绕通知-前置");
        Object result = joinPoint.proceed();
        log.error("环绕通知-后置");
        return result;
    }
    // 返回后通知
    @AfterReturning("execution(* com.briup.jd2511.jd2511bookstore.service.impl.*.*(..))")
    public void afterReturning(JoinPoint joinPoint){
        log.error("返回后通知");
    }
    // 异常后通知
    @AfterThrowing("execution(* com.briup.jd2511.jd2511bookstore.service.impl.*.*(..))")
    public void afterThrowing(JoinPoint joinPoint){
        log.error("异常通知");
    }
}
